<template>
  <div class="el-main">
    <el-form ref="form" :model="leader" :rules="rules" label-width="120px">
      <el-form-item label="领导名称" prop="name">
        <el-input v-model="leader.name"></el-input>
      </el-form-item>
      <el-form-item label="研究方向" prop="research">
        <el-input v-model="leader.research"></el-input>
      </el-form-item>
      <el-form-item label="职称" prop="title">
        <el-input v-model="leader.title"></el-input>
      </el-form-item>
      <el-form-item label="简介" prop="introduce">
        <el-input v-model="leader.introduce" type="textarea"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit('form')">保存</el-button>
        <el-button @click="exit()">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  import {uploadImgToBase64} from '@/utils/fileUtils'
  import Qs from 'qs';

  export default {
    name: "doctorAdd",
    data() {
      return {
        parentId: 0,
        //options: [],
        departmentList: [],
        fileList: [],
        departmentId: '',
        posterUrl: '',
        imgUrls: [],
        imgWidth: '320',
        imgHeight: '400',
        imgBroadcastList: [], // 储存选中   的图片列表
        rules: {
          name: [
            { required: true, message: '请输入活动名称', trigger: 'blur' },
            { min: 3, max: 7, message: '长度在 3 到 7 个字符', trigger: 'blur' }
          ],
        },
        leader: {
          name: "",
          research: "",
          title: "",
          introduce: ""
        }
      }
    },
    methods: {
      handleChange(value) {
        console.log(value);
      },
      findAll() {
        let data = Qs.stringify({parentId: this.parentId})
        this.instance.get('/w/departments/findAll'
        ).then(data => {
          this.departmentList = data.data;
        })
      },
      // 级联关系
      /*     getMenus: function () {
               let data = Qs.stringify({parentId: this.parentId})
               this.instance.post('/w/departments/departmentMenus', data
               ).then(data => {
                   let menus = data.data;
                   if (this.parentId === 0) {
                       this.options = menus;
                   }
               })
           },*/
      onSubmit(formName) {
        let that = this;
        that.$refs[formName].validate((valid) => {
          if (valid) {

            this.instance.post('/w/leaders', this.leader)
              .then(function (response) {
                that.$router.push({name: 'leader'})
              })
              .catch(function (error) {
                console.log(error);
              });
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },


      exit() {
        this.$router.push({name: 'leader'}) // 只能用 name
      }

    },
    mounted() {

    },
    created() {
      let that = this;
      //that.getMenus();
      that.findAll();
      if (!!that.$route.query.doctor) {
        that.doctor = that.$route.query.doctor
       that.departmentId= that.doctor.departmentId;
        that.doctor.departmentId=Number(that.departmentId)
      }
    }
  }
</script>

<style scoped lang="scss">

  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }

  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }

  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>
